Skip to content

cmake: Replace PYTHON_EXECUTABLE alias with Python3_EXECUTABLE - #8285

Merged
echoix merged 1 commit into
OSGeo:mainfrom
echoix:claude/jolly-thompson-lsvcu3
Nov 30, 2026
Merged

echoix merged 1 commit into
OSGeo:mainfrom
echoix:claude/jolly-thompson-lsvcu3

Conversation

@echoix

@echoix echoix commented Nov 28, 2026

Copy link
Copy Markdown
Member

Replaces the PYTHON_EXECUTABLE and PYTHON_SITEARCH aliases, copied from Python3_* in CheckDependentLibraries.cmake, with the Python3_EXECUTABLE and Python3_SITEARCH variables from find_package(Python3). Also removes the commented-out PythonLibs/Numpy block.

Addon builds run against an installed GRASS and never include CheckDependentLibraries.cmake, so build_addon.cmake now calls find_package(Python3 REQUIRED COMPONENTS Interpreter) itself. g.extension now passes -DPython3_EXECUTABLE=<sys.executable>, which FindPython3 uses as the interpreter to find. The ctypesgen sub-script keeps its own PYTHON_EXECUTABLE input name.

I used ${Python3_EXECUTABLE} everywhere rather than Python3::Interpreter, since almost all uses follow ${grass_env_command} and are not the first word of the COMMAND.

Tested with a CMake build (GUI off, since wxPython is not installed) and cmake --install:

  • The build, including the ctypesgen libraries and the docs commands, uses the found interpreter; grass.lib imports.
  • g.extension built and installed addons from grass-addons against the installed tree: r.accumulate (C, OpenMP, images), d.frame and r3.to.group (script and compiled), and the r.dem wrapper with its ten sub-addons. All produced the HTML, man and Markdown docs, and the installed tools run with --help.
  • Configuring an addon directly, without g.extension, shows the new find_package is needed, for script and C addons alike. Without it the variable is empty and the docs commands only run through the script shebang. With it they use the found interpreter.
  • With the GUI on, configure succeeds and the generated compileall commands use the found interpreter. The GUI build itself was not run.
  • pre-commit passes.

None of the grass-addons CMakeLists.txt files reference PYTHON_EXECUTABLE. The only build error is man/GUI_WXPYTHON missing when the GUI is off, which is unrelated and already noted by a TODO in man/CMakeLists.txt.

AI assistance was used to make and review the change.

Suggested squash commit message
cmake: Replace PYTHON_EXECUTABLE alias with Python3_EXECUTABLE

Use the variables of find_package(Python3) directly and drop the
FindPythonInterp-style aliases PYTHON_EXECUTABLE and PYTHON_SITEARCH.

Addon builds run against an installed GRASS and never include
CheckDependentLibraries, so build_addon now calls find_package(Python3)
itself. g.extension passes its interpreter as Python3_EXECUTABLE, which
FindPython3 uses as the interpreter to find.

@echoix
echoix requested a review from nilason November 28, 2026 18:45
Use the variables of find_package(Python3) directly and drop the
FindPythonInterp-style aliases PYTHON_EXECUTABLE and PYTHON_SITEARCH.

Addon builds run against an installed GRASS and never include
CheckDependentLibraries, so build_addon now calls find_package(Python3)
itself. g.extension passes its interpreter as Python3_EXECUTABLE, which
FindPython3 uses as the interpreter to find.
@github-actions github-actions Bot added GUI wxGUI related Python Related code is in Python translation Message translation related libraries module docs general CMake labels Nov 28, 2026
@echoix
echoix force-pushed the claude/jolly-thompson-lsvcu3 branch from 5722fdd to 300e5ca Compare November 28, 2026 18:45
@echoix
echoix merged commit 3b1496f into OSGeo:main Nov 30, 2026
30 of 32 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Nov 30, 2026
petrasovaa added a commit to petrasovaa/grass that referenced this pull request Dec 2, 2026
Since the rename in OSGeo#8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works on
Linux and macOS, where run.py is executable and has a shebang, but on
Windows every grass.lib module fails with "inappropriate file type or
format". Pass the variable under the name the script uses.

The error message was also empty when ctypesgen produced no output,
which is what happens when it cannot start, so include the exit code.
petrasovaa added a commit to petrasovaa/grass that referenced this pull request Dec 2, 2026
Since the rename in OSGeo#8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works on
Linux and macOS, where run.py is executable and has a shebang, but on
Windows every grass.lib module fails with "inappropriate file type or
format". Pass the variable under the name the script uses.

The error message was also empty when ctypesgen produced no output,
which is what happens when it cannot start, so include the exit code.
petrasovaa added a commit to petrasovaa/grass that referenced this pull request Dec 2, 2026
Since the rename in OSGeo#8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works on
Linux and macOS, where run.py is executable and has a shebang, but on
Windows every grass.lib module fails with "inappropriate file type or
format". Pass the variable under the name the script uses.

The error message was also empty when ctypesgen produced no output,
which is what happens when it cannot start, so include the exit code.
petrasovaa added a commit to petrasovaa/grass that referenced this pull request Dec 2, 2026
Since the rename in OSGeo#8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works on
Linux and macOS, where run.py is executable and has a shebang, but on
Windows every grass.lib module fails with "inappropriate file type or
format". Pass the variable under the name the script uses.

The error message was also empty when ctypesgen produced no output,
which is what happens when it cannot start, so include the exit code.
petrasovaa added a commit to petrasovaa/grass that referenced this pull request Dec 2, 2026
Since the rename in OSGeo#8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works on
Linux and macOS, where run.py is executable and has a shebang, but on
Windows every grass.lib module fails with "inappropriate file type or
format". Pass the variable under the name the script uses.

The error message was also empty when ctypesgen produced no output,
which is what happens when it cannot start, so include the exit code.
petrasovaa added a commit that referenced this pull request Dec 3, 2026
Since #8285, the custom command passes the interpreter to
ctypesgen.cmake as PYTHON_EXECUTABLE while the script reads
Python3_EXECUTABLE, so the script ran run.py on its own. That works
where run.py is executable with a shebang, but on Windows every
grass.lib module fails. Pass the variable under the name the script
uses, require it in the script so that a mismatch fails at once, and
include the command and exit code in the error message, which was
empty in this case.

Drafted with Claude Code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake docs general GUI wxGUI related libraries module Python Related code is in Python translation Message translation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants